﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="EditMenu.aspx.cs" Inherits="IsPay.View.EditMenu" %>
<%@ Import Namespace="DataServer.Entities" %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>菜单编辑页面</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- Bootstrap 使用了2的,IE兼容性更好-->
    <link href="../bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
    <script src="../Scripts/jquery-1.10.2.min.js"></script>
    <script src="../bootstrap/js/bootstrap.min.js"></script>

    <script type="text/javascript">
        function AddNewTableRow() {
            var tableObj = document.getElementById("menumodifytable");
            tableObj.insertRow(1);
            tableObj.rows[1].insertCell().innerHTML = "<input type=\"checkbox\" style=\"width: 20px\" checked=\"checked\"/>";
            tableObj.rows[1].insertCell().innerHTML = "<input type=\"checkbox\" style=\"width: 20px\" />";
            tableObj.rows[1].insertCell().innerHTML = "<input type=\"checkbox\" style=\"width: 20px\" />";
            tableObj.rows[1].insertCell().innerHTML = "<input type=\"text\" style=\"border: none; background: transparent\" value=\"\" />";
            tableObj.rows[1].insertCell().innerHTML = "<input type=\"text\" style=\"border: none; background: transparent\" value=\"\" />";
            tableObj.rows[1].insertCell().innerHTML = "<input type=\"text\" style=\"border: none; background: transparent\" value=\"\" />";
        }
        function OnModifyMenu() {
            var jasonstr = "";
            var tableObj = document.getElementById("menumodifytable");
            var ch = new Array();
            var edittable = [];
            for (var i = 0; i < tableObj.rows.length; i++) {    //遍历Table的所有Row
                var dataRow = {};
                for (var j = 0; j < tableObj.rows[i].cells.length; j++) {   //遍历Row中的每一列

                    var cellv = "";
                    var cnode = tableObj.rows[i].cells[j].getElementsByTagName("input");
                    if (cnode.length > 0) {
                        if (cnode[0].type == "checkbox") {
                            cellv = cnode[0].checked;
                        } else {
                            cellv = cnode[0].value;
                        }

                    } else {
                        cellv = tableObj.rows[i].cells[j].innerText.trim();
                    }
                    if (i == 0) {
                        ch[j] = cellv;
                    } else {
                        dataRow[ch[j]] = cellv;
                    }
                }
                if (i > 0) {
                    if (dataRow.addflag || dataRow.modifyflag || dataRow.deleteflag)
                        edittable.push(dataRow);
                }

            }
            jasonstr = JSON.stringify(edittable);
            document.getElementById("updatejason").value = jasonstr;
            document.getElementById("formtable").submit();
            //setTimeout(function(){ document.getElementById("formquery").submit(); }, 5000);
        }

    </script>
</head>
<body>
    <div class="container-fluid">
        <div class="row-fluid">
            <div class="span12">
                <form id="formquery" method="post" action="EditMenu.aspx?ActionType=query">
                    <table>
                        <tr>
                            <td style="text-align: right" class="auto-style2">菜单ID</td>
                            <td class="auto-style2">
                                <input type="text" id="txtmenuid" name="txtmenuid" value="" style="border-color: #000000" /></td>
                            <td style="text-align: right" class="auto-style2">菜单名</td>
                            <td class="auto-style2">
                                <input type="text" id="txtmenuname" name='txtmenuname' style="border-color: #000000" value="" /></td>
                            <td class="auto-style2">&nbsp;&nbsp;&nbsp;&nbsp;
                                <button type="submit" class="btn btn-primary" data-toggle="button">查询</button></td>
                        </tr>
                    </table>
                </form>
            </div>
            <form id="formtable" method="post" action="EditMenu.aspx?ActionType=modify">
                <div class="span12">
                     <input type="hidden" id="updatejason" name="updatejason" value="" />
                    <button type="button" class="btn btn-primary" data-toggle="button" style="float:left" onclick="AddNewTableRow()">添加</button>
                    <button type="button" class="btn btn-primary" data-toggle="button" style="float:left" onclick="OnModifyMenu()">保存</button>
                </div>
                <div class="span12">
                    <asp:Label ID="lblMsg" runat="server" Text="" BackColor="#CC3300" Font-Bold="True"></asp:Label>
                </div>
                <div class="span12" >
                    <table class="table table-striped" id="menumodifytable">
                        <tr>
                            <th>
                                <input type="hidden" name="headcell3" id="headcell3" value="addflag" />添加</th>
                            <th>
                                <input type="hidden" name="headcell6" id="headcell6" value="modifyflag" />修改</th>
                            <th>
                                <input type="hidden" name="headcell7" id="headcell7" value="deleteflag" />删除</th>
                            <th>
                                <input type="hidden" name="headcell1" id="headcell1" value="menuid" />菜单ID</th>
                            <th>
                                <input type="hidden" name="headcell2" id="headcell2" value="menuname" />菜单名</th>
                            <th>
                                <input type="hidden" name="headcell5" id="headcell5" value="htmlname" />HtmlName</th>
                        </tr>
                        <%if (lsmenus != null && lsmenus.Count() > 0)
                            {
                                int i = 0;%>
                        <%foreach (DataServer.Entities.Menu mu in lsmenus)
                            {%>
                        <tr>
                            <td>
                                <input type="checkbox" style="width: 20px" /></td>
                            <td>
                                <input type="checkbox" style="width: 20px" /></td>
                            <td>
                                <input type="checkbox" style="width: 20px" /></td>
                            <td><%=mu.MenuId%></td>
                            <td>
                                <input type="text" style="border: none; background: transparent" value="<%=mu.MenuName %>" /></td>
                            <td>
                                <input type="text" style="border: none; background: transparent" value="<%=mu.HtmlName %>" /></td>                            

                        </tr>
                        <%i++;
                            } %>
                        <%} %>
                    </table>
                </div>
            </form>

        </div>
    </div>
</body>
</html>
